package  
{
	import flash.display.Shape;
	import flash.events.MouseEvent;
	import flash.events.NetStatusEvent;
	import flash.external.ExternalInterface;
	import flash.filters.DropShadowFilter;
	import flash.text.TextFieldAutoSize;
	import flash.utils.setTimeout;
	import ginger.ui.simple.SimpleLayout;
	import ginger.ui.simple.SimpleVideoPlayer;
	import UILib.ControlPanel;
	/**
	 * ...
	 * @author Ning
	 */
	public class VideoPlayer extends SimpleVideoPlayer
	{
		private var _controller:ControlPanel;
		
		private var _isPlay:Boolean;
		public function set isPlay(value:Boolean):void {
			_isPlay = value;
			_controller.playBtn.visible = !isPlay;
			_controller.pauseBtn.visible = isPlay;

			if (isPlay)
			    resume();
			else 
			    pause();
		}
		public function get isPlay():Boolean {
			return _isPlay;
		}
		
		override public function play(url:String = null):void 
		{
			stop();
			super.play(url);
			this.isPlay = true;
		}
		
		public function VideoPlayer() 
		{
			super(693, 385);
			this.isPlay = false;
			
			_controller.playBtn.addEventListener(MouseEvent.CLICK, onPlay);
			_controller.pauseBtn.addEventListener(MouseEvent.CLICK, onPause);
			_controller.fullBtn.addEventListener(MouseEvent.CLICK, onFullScreen);
			
		}
		override protected function configUI():void 
		{
			super.configUI();
			
			_controller = new ControlPanel();
			addChild(_controller);
		}
		override protected function drawLayout():void 
		{
			super.drawLayout();
			
			_controller.y = 405;
			_controller.x = 20;
			
			videoContainer.x = 8;
			videoContainer.y = 8;

		}
		
		private function onPlay(evt:MouseEvent):void
		{
			isPlay = true;
		}
		private function onPause(evt:MouseEvent):void
		{
			isPlay = false;
		}
		private function onFullScreen(evt:MouseEvent):void
		{
			this.displayState = SimpleVideoPlayer.FULL_SCREEN;
		}
		
		public function setData(url:String):void
		{
			play(url);
		}
		override public function reset():void 
		{
			this.seek = 0;
			isPlay = false;
		}
		
		override protected function netStatusHandler(event:NetStatusEvent):void 
		{
			switch (event.info.code)
			{
				case "NetStream.Play.Stop" :
				setTimeout(reset, 1000);
				break;
			}
		}	
	}
}